package com.info33.platform;

import com.info33.platform.common.filter.RefererFilter;
import lombok.extern.slf4j.Slf4j;
import net.hasor.spring.boot.EnableHasor;
import net.hasor.spring.boot.EnableHasorWeb;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * EnableTransactionManagement 启注解事务管理，等同于xml配置方式的 <tx:annotation-driven />
 *
 * @author Administrator
 */
@SpringBootApplication
@ServletComponentScan(basePackageClasses = RefererFilter.class)
@EnableHasor
@EnableHasorWeb
@EnableScheduling
@EnableTransactionManagement
@EnableCaching
@Slf4j
public class PlatformApplication {

    public static void main(String[] args) throws UnknownHostException {
        final ConfigurableApplicationContext run = SpringApplication.run(PlatformApplication.class, args);
        Environment env = run.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();

        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        log.info("\n----------------------------------------------------------\n\t" +
                "33 SpringBoot is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger-ui:\thttp://" + ip + ":" + port + path + "/swagger-ui/#/\n\t" +
                "Doc文档: \thttp://" + ip + ":" + port + path + "/doc.html\n\t" +
                "Druid 监制页面: \thttp://" + ip + ":" + port + path + "/druid/sql.html\n" +
                "----------------------------------------------------------");
    }

}
